<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../../common/base_body_header.jsp" %>
<%@include file="../../common/navbar.jsp" %>
<%@include file="../../common/page_content_pre.jsp" %>
<style>
.dataTable{
	text-align:center;
}
</style>
<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal" role="form" action="${GLOBAL.basePath}/systemUser/list" method="post">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-1 control-label" for="s_account">手机号</label>

                        <div class="col-sm-2">
                            <input class="form-control" id="s_account" name="account" type="text" placeholder="请输入账户"
                                   value="${sysUser.account}"/>
                        </div>
                        <label class="col-sm-1 control-label" for="s_username">姓名</label>

                        <div class="col-sm-2">
                            <input class="form-control" id="s_username" type="text" name="username" placeholder="请输入姓名"
                                   value="${sysUser.username}"/>
                        </div>
                        <div class="col-sm-2">
                            <button class="btn btn-primary btn-sm" onsubmit="return false;">
                                查询
                                <i class="icon-search align-top bigger-125 icon-on-right"></i>
                            </button>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
         <shiro:hasPermission name="sys:systemUser:edit">
            <div class="col-sm-12">
                <button class="btn btn-xs btn-success" id="add_btn">添加
                    <i class="icon-plus align-top bigger-125 icon-on-right"></i>
                </button>
            </div>
        </shiro:hasPermission>
        <div class="col-xs-12">
            <div class="table-responsive">
                <table id="list-table" class="table table-striped table-bordered table-hover" width="100%">
                    <thead>
                    <tr>
                        <th>
                            <label>
                                <input type="checkbox" class="ace"/>
                                <span class="lbl"></span>
                            </label>
                        </th>
                        <th style="text-align:center;">用户编号</th>
                        <th style="text-align:center;">姓名</th>
                        <th style="text-align:center;">手机号</th>
                        <th style="text-align:center;">地址</th>
                        <th style="text-align:center;">角色</th>
                        <th style="text-align:center;">状态</th>
                        <th style="text-align:center;">
                            <i class="icon-time bigger-110 hidden-480"></i>
                            创建时间
                        </th>
                        <th style="text-align:center;">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<%@include file="../../common/page_content_suf.jsp" %>
<%@include file="../../common/script.jsp" %>

<script type="text/javascript">

    var userListTable;

    jQuery(function ($) {

        $("#add_btn").on("click", function () {
            addClick();
        });

        $('.date-picker').datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        userListTable = $('#list-table').dataTable({
            "sAjaxSource": "${GLOBAL.basePath}/systemUser/asynList",
            "fnServerData": function (sSource, aDataSet, fnCallback) {
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aDataSet,
                    "success": fnCallback,
                    "beforeSend": function (XMLHttpRequest) {
                        layer.load();
                    },
                    "complete": function (XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    }
                });
            },
            "fnServerParams": function (aoData) {//向服务器传额外的参数
                <c:if test="${not empty aoData}">
                aoData.push(${aoData});
                </c:if>
            },
            "bSort": false,
            "bFilter": false,
            "bServerSide": true,
            "bProcessing": false,
            "bLengthChange": false,
            "bSearching": false,
            "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
            "oLanguage": {
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
                "sInfoEmpty": "No data"
            },
            "aoColumns": [
                {
                    "sName": "id", "mDataProp": "userId", "sWidth": "60px", "mRender": function (data, type, full) {
                    return "<label>"
                            + "<input type='checkbox' class='ace' value='" + data + "' />"
                            + "<span class='lbl'></span>"
                            + "</label>";
                }
                },
                {"mDataProp": "userId", "sWidth": "100px"},
                {"mDataProp": "username", "sWidth": "120px"},
                {"mDataProp": "account", "sWidth": "120px"},
                {"mDataProp": "address", "sWidth": "150px"},
                {"mDataProp": "userRole", "sWidth": "150px"},
                
                {
                    "mDataProp": "status", "sWidth": "100px", "mRender": function (data, type, full) {
                    if (data == 0) {
                        return "正常";

                    } else if(data==1) {
                        return "冻结";
                    }else{
                    	return "";
                    }
                }
                },
                {"mDataProp": "createDate", "sWidth": "150px"},
                {
                    "mDataProp": "userId", "sWidth": "220px", "mRender": function (data, type, full) {
                    if (full.status == '0') {
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='detailClick(this)'>详情</button>"
                                + "<shiro:hasPermission name='sys:user:edit'>"
                                + "<button class='football-edit btn btn-xs btn-danger' pkId='" + data + "' onclick='editClick(this)' style='margin-left:20px;'>修改</button>"
                                +"<button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='delClick(this)' style='margin-left:20px;'>冻结</button>"
                                +"<button class='football-edit btn btn-xs btn-danger' pkId='" + data + "' onclick='initClick(this)' style='margin-left:20px;'>初始化密码</button>"
                                + "</shiro:hasPermission>"
                                + "</div>";
                    } else {
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                + "<button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='detailClick(this)'>详情</button>"
                                + "<shiro:hasPermission name='sys:user:edit'>"
                                + "<button class='football-edit btn btn-xs btn-danger' pkId='" + data + "' onclick='editClick(this)' style='margin-left:20px;'>修改</button>"
                                + "<button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='thaw(this)' style='margin-left:20px;'>解冻</button>"
                                +"</shiro:hasPermission>"
                                + "</div>";
                    }
                }
                }
            ]
        });
    });


    var addClick = function () {
        document.location.href = "${GLOBAL.basePath}/systemUser/add";
    };

    var editClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/systemUser/edit?userId=" + $(obj).attr("pkId");
    };

    var detailClick = function (obj){
        document.location.href = "${GLOBAL.basePath}/systemUser/detail?id=" + $(obj).attr("pkId");
    }

    var delClick = function (obj) {
        layer.confirm("确定要冻结此用户吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/systemUser/delete", "POST", {id: $(obj).attr("pkId")});
            if(result==1){
               layer.alert("冻结成功", {icon: 1, title: '提示', btn: ['OK']});
               userListTable.fnDraw();
            }else{
            	layer.alert("操作失败", {icon: 1, title: '提示', btn: ['NO']});
            }
        })
    };

    var thaw = function (obj) {
        layer.confirm("确定要解冻此用户吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/systemUser/thaw", "POST", {id: $(obj).attr("pkId")});
            if(result==1){
            	layer.alert("解冻成功", {icon: 1, title: '提示', btn: ['OK']});
                userListTable.fnDraw();
            }else{
            	layer.alert("操作失败", {icon: 1, title: '提示', btn: ['NO']});
            }
            
        })
    };
    
   var initClick=function(obj){
	   layer.confirm("确定要初始化密码吗？", {
           title: '提示',
           btn: ['确认', '取消'], //按钮
           area: ['auto', 'auto'] //宽高
       }, function () {
           var result = ART.mAjax("${GLOBAL.basePath}/systemUser/initPass", "POST", {id: $(obj).attr("pkId")});
           if(result==1){
           	layer.alert("初始化成功，密码为000000", {icon: 1, title: '提示', btn: ['OK']});
               userListTable.fnDraw();
           }else{
           	layer.alert("操作失败", {icon: 1, title: '提示', btn: ['NO']});
           }
           
       })
   };
</script>
